package com.my12306.common.model.vo;

import lombok.Data;

import java.io.Serializable;
import java.util.Objects;

/**
 * @Author:苏牧夕
 * @Date:2020/5/29 23:02
 * @Version 1.0
 */
@Data
public class PageVo implements Serializable {
    /**
     * 第几页下标
     */
    private Integer page;
    /**
     * 页面大小
     */
    private Integer limit;
    /**
     * 模糊查询的内容
     */
    private String likeName;
    /**
     * 分页起始id;
     */
    private Integer startIndex;
    /**
     * 用于查询一段范围的数据
     * 开始时间
     */
    private String startDate;
    private Long userId;
    /**
     * 结束时间
     */
    private String endDate;

    public PageVo() {
    }

    public PageVo(Integer page, Integer limit, String likeName, Integer startIndex, String startDate, String endDate) {
        this.page = page;
        this.limit = limit;
        this.likeName = likeName;
        this.startIndex = startIndex;
        this.startDate = startDate;
        this.endDate = endDate;
    }

    /**
     * 对于空的实现初始化
     *
     * @return
     */
    public PageVo init() {
        if (this.getLimit() == null || this.getPage() == null) {
            this.setLimit(10);
            this.setPage(1);
        }
        this.setStartIndex((this.getPage() - 1) * this.getLimit());
        return this;
    }

    @Override
    public String toString() {
        return "PageVo{" +
                "page=" + page +
                ", limit=" + limit +
                ", likeName='" + likeName + '\'' +
                ", startIndex=" + startIndex +
                ", startDate=" + startDate +
                ", endDate=" + endDate +
                '}';
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (!(o instanceof PageVo)) return false;
        PageVo pageVo = (PageVo) o;
        return Objects.equals(getPage(), pageVo.getPage()) &&
                Objects.equals(getLimit(), pageVo.getLimit()) &&
                Objects.equals(getLikeName(), pageVo.getLikeName()) &&
                Objects.equals(getStartIndex(), pageVo.getStartIndex()) &&
                Objects.equals(getStartDate(), pageVo.getStartDate()) &&
                Objects.equals(getEndDate(), pageVo.getEndDate());
    }

    @Override
    public int hashCode() {
        return Objects.hash(getPage(), getLimit(), getLikeName(), getStartIndex(), getStartDate(), getEndDate());
    }

    public Integer getPage() {
        return page;
    }

    public void setPage(Integer page) {
        this.page = page;
    }

    public Integer getLimit() {
        return limit;
    }

    public void setLimit(Integer limit) {
        this.limit = limit;
    }

    public String getLikeName() {
        return likeName;
    }

    public void setLikeName(String likeName) {
        this.likeName = likeName;
    }

    public Integer getStartIndex() {
        return startIndex;
    }

    public void setStartIndex(Integer startIndex) {
        this.startIndex = startIndex;
    }

    public String getStartDate() {
        return startDate;
    }

    public void setStartDate(String startDate) {
        this.startDate = startDate;
    }

    public String getEndDate() {
        return endDate;
    }

    public void setEndDate(String endDate) {
        this.endDate = endDate;
    }
}
